#include "widget.h"
#include "ui_widget.h"
#include "pgwslidewidget.h"

#include <QFileDialog>
#include <QDir>
#include <QDebug>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    m_slideWidget = new PgwSlideWidget(this);
    ui->scrollArea->setWidget(m_slideWidget);
    ui->scrollArea->setWidgetResizable(true);
    setWindowTitle("PgwSlideWidget demo");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_browseBtn_clicked()
{
    QString imageDir = QFileDialog::getExistingDirectory(this, tr("Browse image directory"));
    if (imageDir.isEmpty())
        return;

    ui->dirEdit->setText(imageDir);
    QDir dir(imageDir);
    QStringList imageFiles = dir.entryList(QStringList() << "*.png" << "*.jpg" << "*.jpeg", QDir::Files);

    QStringList fullImageFiles;
    foreach (const QString& img, imageFiles)
        fullImageFiles.append(QString("file:///%1/%2").arg(imageDir).arg(img));
    qDebug() << fullImageFiles;

    m_slideWidget->setImages(fullImageFiles);
    m_slideWidget->render();

}
